//
//  FenXiangXiangQiuTableViewCell.m
//  XiangMu
//
//  Created by 康世标 on 15/8/27.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "FenXiangXiangQiuTableViewCell.h"
#import "Masonry.h"
#import "Header.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
@implementation FenXiangXiangQiuTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    [self.hedImagView.layer setMasksToBounds:YES];
    [self.hedImagView.layer setCornerRadius:30];
    
}
- (void)ImgageView:(NSArray *)arr Datas:(NSMutableDictionary *)datas{
    
    self.lable.text = [datas valueForKey:@"info"];
    
    self.lable1.text = [datas valueForKey:@"nickname"]==[NSNull null]?@"":[datas valueForKey:@"nickname"];
    self.lable2.text = [self upDated:[[datas valueForKey:@"updated"]==[NSNull null]?@"":[datas valueForKey:@"updated"] longLongValue]];
    
    if ([datas valueForKey:@"headImg"]==[NSNull null]) {
        
        
    }
    else{
          [self.hedImagView sd_setBackgroundImageWithURL:[NSURL URLWithString:[datas valueForKey:@"headImg"]] forState:UIControlStateNormal];
    }
  
    
       CGRect rect = [[datas valueForKey:@"info"] boundingRectWithSize:CGSizeMake(kScreenW-8, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:14]} context:nil];

    for (int i = 0; i<arr.count; i ++) {
        
        NSLog(@"--dd-%@",arr[i]);
        
        self.labelLaYout.constant = arr.count*200+(arr.count*10);
        
        UIImageView * imageView = [[UIImageView alloc]init];
        
         NSString * newUrl = [[arr objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        
        imageView.contentMode = UIViewContentModeScaleToFill;
        
        UIImageView * newImage = [[UIImageView alloc]init];
        
        
        [newImage sd_setImageWithURL:[NSURL URLWithString:newUrl] placeholderImage:[UIImage imageNamed:@"like"]];
        
        
        imageView.image = [self imageWithImageSimple:newImage.image scaledToSize:CGSizeMake(kScreenW-16, 200)];
        
        
        [self.contentView addSubview:imageView];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.contentView).with.offset(8);
//            make.right.equalTo(self.contentView).with.offset(8);
            make.top.equalTo(self.lable).with.offset(rect.size.height+20+i*200+(i%arr.count)*10);
            make.size.mas_equalTo(CGSizeMake(kScreenW-16, 200));
        }];
    }
}
-(NSString *)upDated:(long long)str{
    
    if (str==0) {
        
        return @"";
    }
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:str/1000];
    
    NSDateFormatter * dataFormatter = [[NSDateFormatter alloc]init];
    
    [dataFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString * string= [dataFormatter stringFromDate:date];
    
    return string;
    
}
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    // Return the new image.
    return newImage;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
